def prost(s):
    chis=[]
    for n in range(1,s+1):
        flag=0
        for i in range(2,n//2+1):
            if n%i==0:
                flag=1
        if flag ==0:
            chis.append(str(n))
    return chis

s=input()
k=0
a=[]
try:
    k=int(s)
    if (999<k<10000):
        for x in prost(k):
            if x in s:
                a.append(int(x))
        print(max(a))
    else:
        print(0)
except:
    print(0)
